<!--  -->
<template>
  <div class="role">
    <div class="navheader borderbox">
      <img src="../assets/img/icon-back.png" class="back" @click="toMemberView" />
      <div class="title">VIP会员</div>
    </div>
    <div class="line"></div>
    <div class="user-info">
      <div class="avatar">
        <img :src="avatar" />
      </div>
      <div class="role-info">
        <div class="info">
          <div>您的月度会员2023-08-14 16:56:56到期</div>
          <div>购买后将会有效期顺延</div>
        </div>
      </div>
    </div>
    <div class="role-item-box">
      <div class="role-item" v-for="item in vip" :key="item.id">
        <div class="name">{{ item.name }}</div>
        <div class="price"><span class="small">￥</span>{{ item.charge }}</div>
        <div class="desc">
          <div>{{ item.desc_rows[0] }}</div>
        </div>
      </div>
    </div>
    <div class="bottom-bar">购买会员</div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      vip: [],
      avatar: "",
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    toMemberView() {
      this.$router.go(-1);
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  async created() {
    let res = await this.$request
      .get("/api/v2/roles")
      .then((res) => {
        console.log(res);
        this.vip = res.data;
      })
      .catch((err) => {
        console.log(err);
      });
    let detaile = await this.$request
      .get("/api/v2/member/detail")
      .then((res) => {
        console.log(res);
        this.avatar = res.data.avatar;
      })
      .catch((err) => {
        console.log(err);
      });
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang="less" scoped>
.role {
  box-sizing: border-box;
  padding-top: 50px;
  background: #f6f6f6;
  position: absolute;
  left: 0;
  top: 0;
  overflow-y: scroll;
  overflow-x: hidden;
  width: 100%;
  height: 100%;
  .navheader.borderbox {
    position: fixed;
    top: 0;
    width: 100%;
    height: 50px;
    background-color: #fff;
    z-index: 100;
    padding-left: 15px;
    padding-right: 15px;
    display: flex;
    flex-direction: row;
    justify-content: center;
    border-bottom: 1px solid #f1f2f6;
    align-items: center;
    -webkit-box-sizing: border-box;
    .back {
      position: absolute;
      left: 15px;
      width: 19px;
      height: 19px;
    }

    .title {
      width: 72%;
      height: auto;
      font-size: 17px;
      font-weight: 500;
      text-align: center;
      color: #333;
      line-height: 22px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
  .line {
  }
  .user-info {
    width: 100%;
    height: auto;
    float: left;
    display: flex;
    padding: 20px 15px;
    box-sizing: border-box;
    margin-top: 15px;
    margin-bottom: 15px;
    background-color: #fff;
    .avatar {
      width: 48px;
      height: 48px;
      border-radius: 50%;
      img {
        width: 48px;
        height: 48px;
        border-radius: 50%;
      }
    }

    .role-info {
      padding-top: 4px;
      margin-left: 15px;
      flex: 1;
      font-size: 13px;
      font-weight: 400;
      color: #333;
      line-height: 20px;

      .info {
        font-size: 13px;
        font-weight: 400;
        color: #333;
        line-height: 20px;
        div {
          font-size: 13px;
          font-weight: 400;
          color: #333;
          line-height: 20px;
        }
      }
    }
  }

  .role-item-box {
    width: 100%;
    height: auto;
    float: left;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    box-sizing: border-box;
    padding: 15px;
    .role-item {
      width: calc(50% - 5px);
      height: auto;
      float: left;
      padding: 15px;
      box-sizing: border-box;
      border-radius: 8px;
      margin-bottom: 15px;
      border: 1px solid #fff;
      background-color: #fff;
      .name {
        width: 100%;
        height: auto;
        float: left;
        font-size: 14px;
        font-weight: 600;
        color: #e1a500;
        line-height: 14px;
        margin-bottom: 20px;
      }

      .price {
        width: 100%;
        height: auto;
        float: left;
        font-size: 28px;
        font-weight: 600;
        color: #333;
        line-height: 24px;
        margin-bottom: 15px;
        span.small {
          font-size: 28px;
          font-weight: 600;
          color: #333;
          line-height: 24px;
        }
      }

      .desc {
        width: 100%;
        height: auto;
        float: left;
        font-size: 12px;
        font-weight: 400;
        color: #666;
        line-height: 18px;
        div {
          font-size: 12px;
          font-weight: 400;
          color: #666;
          line-height: 18px;
        }
      }
    }
  }

  .bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 49px;
    background-color: #cea200;
    line-height: 49px;
    text-align: center;
    color: #fff;
  }
}
</style>
